package org.vacoor.nothing.web.entity;

import java.io.Serializable;

// @MappedSuperClass
public abstract class AbstractEntity<ID extends Serializable> implements Idable<ID> {
    /**
     * @Id
     * @Column
     */
    protected ID id;

    @Override
    public ID getId() {
        return id;
    }

    public void setId(ID id) {
        this.id = id;
    }

    /**
     * 重写, 根据具体业务来判断是否相等(id)
     *
     * @param other
     * @return
     */
    @Override
    public boolean equals(Object other) {
        if (this == other) return true;
        if (null == other || getClass() != other.getClass()) {
            return false;
        }
        AbstractEntity that = (AbstractEntity) other;
        return getId() == that.getId() || (null != getId() && getId().equals(that.getId()));
    }

    @Override
    public int hashCode() {
        return id != null ? id.hashCode() : 0;
    }

}